using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace XDL.Framework.Screens
{
    /// <summary>
    /// Base class for the "dialog-box"-style UI.
    /// </summary>
    /// <remarks>
    /// The dialog box contains standard menu items.
    /// </remarks>
    public class DialogBoxScreen :
        DialogMenuScreen
    {
        SpriteFont m_font;

        public class DialogBoxResultEventArgs :
            EventArgs
        {
            public readonly bool Result;
            public DialogBoxResultEventArgs(bool res)
            {
                Result = res;
            }
        }
        public delegate void OnExitHandler(object sender, DialogBoxResultEventArgs e);

        /// <summary>
        /// Raised when the dialog box is closed.
        /// </summary>
        public event OnExitHandler OnExit;

        /// <summary>
        /// Creates a new dialog box.
        /// </summary>
        /// <remarks>
        /// The screen is a popup and transition time is set to 0.25s by default.
        /// </remarks>
        public DialogBoxScreen()
        {
            //
            TransitionOnTime = TimeSpan.FromSeconds(0.25);
            TransitionOffTime = TimeSpan.FromSeconds(0.25);

            // Flag that there is no need for the game to transition
            // off when the pause menu is on top of it.
            IsPopup = true;
        }

        public override void LoadContent()
        {
            base.LoadContent();

            // default font
            m_font = GameServices.LoadContent<SpriteFont>("2d/Fonts/Normal");
        }

        /// <summary>
        /// When the user cancels the dialog box, resume the game or cancel the selection action (if any).
        /// </summary>
        protected override void OnCancel()
        {
            ExitScreen(false);
        }

        public void ExitScreen(bool result)
        {
            ExitScreen();
            if (OnExit != null)
            {
                DialogBoxResultEventArgs e = new DialogBoxResultEventArgs(result);
                OnExit(this, e);
            }
        }
    }
}
